<%--
  Created by IntelliJ IDEA.
  User: cjbi
  Date: 2018/4/6
  Time: 7:43
  空页面.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!-- Content Header (Page header) -->
<section class="content-header" style="">
    <h1>
        ${archives.comName}
        <small>修改密码</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
        <li><a href="#">个人信息</a></li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <!-- Default box -->
    <div class="box">

        <div class="box-body">
            <div class="col-xs-12 col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">个人信息</div>
                    <div class="panel-body">
                        <ul>
                            <li>编号：${personal.id}</li>
                            <li>登录名称：${personal.username}</li>
                            <li>真实姓名：${personal.reallyName}</li>
                           <%-- <li>授信额度：${personal.creditLine}</li>--%>
                           <li>身份：${personal.userType}</li>
                           <%-- <li>状态：${personal.status}</li>--%>
                            <li>电话：${personal.phone}</li>
                            <li>创建时间：${personal.createDate}</li>
                            <li>更新时间：${personal.updateDate}</li>
                            <li>所属部门：${personal.organizationName}</li>

                        </ul>
                        <button id="pass" onclick="modifiPass(${personal.id})"> 修改密码</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.box-body -->
        <%-- <div class="box-footer">
             页脚
         </div>--%>
        <!-- /.box-footer-->
    </div>
    <!-- /.box -->

</section>


<!-- add Modal -->
<div class="modal fade" id="modifiModal" tabindex="-1" role="dialog" aria-labelledby="modifiModalLabel"
>
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modifiModalLabel">修改密码</h4>
            </div>
            <div class="modal-body">
                <form id="modifiForm" >
                    <input type="hidden" id="user_id" name="id" readonly required>
                    <div class="form-group">
                        <label class="control-label"><span class="asterisk">*</span>新密码</label>
                        <input id="pwd1" type="password" class="form-control" placeholder="新密码"
                               minlength="6" required>
                        <div class="help-block with-errors"></div>
                    </div>
                    <div class="form-group">
                        <label class="control-label"><span class="asterisk">*</span>确认密码</label>
                        <input id="pwd2" type="password" class="form-control" name="password" placeholder="确认密码"
                               minlength="6" required>
                        <div class="help-block with-errors"></div>
                    </div>
                    <span class="records"></span>
                </form>
            </div>
            <%--<div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id = "modifi_button" type="button" class="btn btn-primary">确定</button>
            </div>--%>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button  id="sub_button" type="button" form="modifiForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#modifiForm',url:'<%=request.getContextPath()%>/user/changePass',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<script>

    $(function () {
        $("#sub_button").attr("disabled", true);
        $("#pwd2").blur(function(){
            var pwd1 = $('#pwd1').val();
            var pwd2 = $('#pwd2').val();
            if(pwd1!=pwd2){
                $("#sub_button").attr("disabled", true);
                $('.records').html('两次输入的密码不一致！');
                //return false;
            }else {
                $('.records').html('');
                $("#sub_button").attr("disabled", false);
            }

            //return true;
        })
    })

    function modifiPass(userID) {
        $('#modifiModal').modal('show')
        $('#user_id').val(userID)
    }
    /*
    $(document).on('click', "#modifi_button",function(){
        if (formCheck()){
            modifiPost()
            event.preventDefault() //阻止form表单默认提交
        };

    });*/

    function formCheck(){
        var pwd1 = $('#pwd1').val();
        var pwd2 = $('#pwd2').val();
        if(pwd1!=pwd2){
            $('.records').html('两次输入的密码不一致！');
            return false;
        }
        return true;
    }

    /*$('#modifiForm').on('submit', function(){
        modifiPost()
        event.preventDefault() //阻止form表单默认提交
    })*/
    function modifiPost () {
        $.ajax({
            type: "post",
            url: <%=request.getContextPath()%>+'/user/changePass',
            data: $('#modifiForm').serialize(),
        }).success(function(message) {
            $.myNotify.success(data.msg);
        }).fail(function(err){
        })
        /*
         或者用jquery.form.min.js提交
         $('#registSubmit').ajaxSubmit(function(message){
         })
         */
    }
</script>